<?php

/**
 * CostumerController
 * 
 * @package Sgit 
 * @author Juan Manuel Martinez Carrillo
 * @copyright Juan Manuel Martinez Carrillo
 * @version 2012
 * @access public
 * @revision 17/02/2012 8:53:55
 */

class CostumerController extends Sgit_Controller_Action
{
    protected $_main_model = 'Costumer';
    protected $_main_form = 'Costumer';


    


    public function indexAction()
    {
        $this->view->rows = $this->_model->default->getCostumer();
    }
    
    


    public function editarAction()
    {
        $this->_editar();
    }

    public function insertarAction()
    {
        $this->_insertar();
    }

    public function borrarAction()
    {
        $this->_borrar();
    }
    
    protected function _getFila($id)
    {
        return $this->_model->default->getCostumer($id);
    }
    
    protected function _prepareValuesToDb(){
        $row=$this->_form->getValues();
        if(!$row['codigo'])  unset($row['codigo']);//key, null if empty
        return $row;
    }
    
    
    /*
    public function copy()
    {
       $this->_helper->layout->disableLayout();
       $this->_helper->viewRenderer->setNoRender(TRUE);
       
       $m_clientes = new Application_Model_Clientes();
       $rows = $m_clientes->getAll();
       
       
       foreach($m_clientes as $v)
       {
             $record['id']=$v['id'];
             $record['nombre']=$v['nombre'];
             $record['cif']=$v['nif'];
             $record['razon_social']=$v['raz_soc'];
             $record['domicilio']=$v['doc_soc'];
             $this->_model->default->insert($record);
       }
       
    }
    
    public function codigo()
    {
       $this->_helper->layout->disableLayout();
       $this->_helper->viewRenderer->setNoRender(TRUE);
       
    
        
        $file = new SplFileObject(APPLICATION_PATH."/Libro1.csv");
        $file->setFlags(SplFileObject::READ_CSV);
        $file->setCsvControl(';');
        
        foreach ($file as $row) {
        
          
          $pepes[$row[3]]=$row[0];
        }


       $rows = $this->_model->default->getCostumer();
       
       foreach($rows as $k => $v)
       {
            foreach($v['pep'] as $g){
               if(is_numeric($g))$rows[$k]['pepe'].=' '.Sgit_Cache::single()->model('Pep')->getKey($g,'pep');
            }
       }
       
       foreach($rows as &$v)
       {
            foreach($pepes as $pep => $codigo)
            {
                if(strpos($v['pepe'],$pep)===false){
                    
                }else{
                    $v['codigo']=$codigo;
                }
            }
       }
       
        foreach($rows as $v)
        {
            if($v['codigo'])
                $this->_model->default->updateRow(array('codigo'=>$v['codigo']),$v['id']);
        }
        
       Sgit_Util_Profiler::run();
       

       
    }
*/
}
